// 万能头文件演示程序
// 编译命令：g++ -o universal_header_demo.exe universal_header_demo.cpp

#include <bits/stdc++.h>
using namespace std;

int main() {
    cout << "万能头文件演示程序" << endl;
    cout << "===================" << endl;
    
    // 1. 输入输出
    cout << "\n1. 输入输出演示" << endl;
    cout << "Hello, World!" << endl;
    
    // 2. 容器演示
    cout << "\n2. 容器演示" << endl;
    
    // vector - 动态数组
    vector<int> vec = {1, 2, 3, 4, 5};
    cout << "vector: ";
    for(int x : vec) cout << x << " ";
    cout << endl;
    
    // string - 字符串
    string str = "Hello C++";
    cout << "string: " << str << endl;
    
    // map - 映射
    map<string, int> mp;
    mp["apple"] = 5;
    mp["banana"] = 3;
    cout << "map: ";
    for(auto& p : mp) {
        cout << p.first << ":" << p.second << " ";
    }
    cout << endl;
    
    // set - 集合
    set<int> s = {5, 2, 8, 1, 3};
    cout << "set: ";
    for(int x : s) cout << x << " ";
    cout << endl;
    
    // 3. 算法演示
    cout << "\n3. 算法演示" << endl;
    vector<int> numbers = {5, 2, 8, 1, 9, 3};
    
    cout << "原始数组: ";
    for(int x : numbers) cout << x << " ";
    cout << endl;
    
    // 排序
    sort(numbers.begin(), numbers.end());
    cout << "排序后: ";
    for(int x : numbers) cout << x << " ";
    cout << endl;
    
    // 查找
    auto it = find(numbers.begin(), numbers.end(), 5);
    if(it != numbers.end()) {
        cout << "找到5，位置: " << distance(numbers.begin(), it) << endl;
    }
    
    // 求和
    int sum = accumulate(numbers.begin(), numbers.end(), 0);
    cout << "数组求和: " << sum << endl;
    
    // 4. 数学函数
    cout << "\n4. 数学函数演示" << endl;
    cout << "sqrt(16) = " << sqrt(16) << endl;
    cout << "pow(2, 3) = " << pow(2, 3) << endl;
    cout << "abs(-5) = " << abs(-5) << endl;
    cout << "max(10, 20) = " << max(10, 20) << endl;
    cout << "min(10, 20) = " << min(10, 20) << endl;
    
    // 5. 时间函数
    cout << "\n5. 时间函数演示" << endl;
    time_t now = time(0);
    cout << "当前时间戳: " << now << endl;
    
    // 6. 随机数
    cout << "\n6. 随机数演示" << endl;
    srand(time(0));
    cout << "随机数: ";
    for(int i = 0; i < 5; i++) {
        cout << rand() % 100 << " ";
    }
    cout << endl;
    
    // 7. 字符串流
    cout << "\n7. 字符串流演示" << endl;
    stringstream ss;
    ss << "Hello " << 123 << " World";
    cout << "字符串流: " << ss.str() << endl;
    
    // 8. 队列和栈
    cout << "\n8. 队列和栈演示" << endl;
    
    // 队列
    queue<int> q;
    for(int i = 1; i <= 3; i++) q.push(i);
    cout << "队列: ";
    while(!q.empty()) {
        cout << q.front() << " ";
        q.pop();
    }
    cout << endl;
    
    // 栈
    stack<int> st;
    for(int i = 1; i <= 3; i++) st.push(i);
    cout << "栈: ";
    while(!st.empty()) {
        cout << st.top() << " ";
        st.pop();
    }
    cout << endl;
    
    // 9. 位运算
    cout << "\n9. 位运算演示" << endl;
    int a = 5, b = 3;
    cout << "a = " << a << " (二进制: " << bitset<8>(a) << ")" << endl;
    cout << "b = " << b << " (二进制: " << bitset<8>(b) << ")" << endl;
    cout << "a & b = " << (a & b) << " (二进制: " << bitset<8>(a & b) << ")" << endl;
    cout << "a | b = " << (a | b) << " (二进制: " << bitset<8>(a | b) << ")" << endl;
    cout << "a ^ b = " << (a ^ b) << " (二进制: " << bitset<8>(a ^ b) << ")" << endl;
    
    // 10. 函数对象
    cout << "\n10. 函数对象演示" << endl;
    function<int(int, int)> add = [](int a, int b) { return a + b; };
    function<int(int, int)> multiply = [](int a, int b) { return a * b; };
    
    cout << "add(3, 4) = " << add(3, 4) << endl;
    cout << "multiply(3, 4) = " << multiply(3, 4) << endl;
    
    cout << "\n万能头文件演示完成！" << endl;
    cout << "可以看到，一个 #include <bits/stdc++.h> 就包含了几乎所有常用的C++库！" << endl;
    
    return 0;
}
